@(projectName: Seq[String], proname: String, host: String)(implicit session: Session)
@fileupload.main("样品管理", projectName, proname, host) {

    <style>
            .update {
                border-radius: 15px 15px 15px 15px;
                background-color: transparent;
                color: gray;
                border: 0px;
            }

            .update:hover {
                color: gray;
                background-color: lightgray;
            }

            .fastq {
                background-color: transparent;
                color: gray;
                border: 0px;
            }

            .fastq:hover {
                color: black;
                text-decoration: underline;
            }

            .delete {
                border-radius: 15px 15px 15px 15px;
                background-color: transparent;
                color: gray;
                border: 0px;
            }

            .delete:hover {
                color: white;
                background-color: red;
            }

            .state {
                display: none;
            }

            .layui-layer-title {
                background-color: #428BCA;
                height: 55px;
            }
    </style>


    <div class="row">
        <div class="col-md-12 col-sm-12">
            <div class="portlet blue-madison box">

                <div class="portlet-title">
                    <div class="caption">
                        样品管理
                    </div>
                </div>


                <div class="portlet-body" id="t">

                    <div class="table-responsive" >

                        <table class="display table table-bordered table-hover table-striped" id="table" data-pagination="true" data-search="true"
                        data-search-align="left" data-page-list="[10, 25, 50, 100]" data-multiple-search="true">

                            <thead>
                                <tr>
                                    <th data-field="sample" data-sortable="true" id="sample">样品名</th>
                                    <th data-field="input_type" data-sortable="true" id="input_type">数据类型</th>
                                    <th data-field="createdate" data-sortable="true" id="createdata">创建时间</th>
                                    <th data-field="state" data-sortable="true" id="state">运行状态</th>
                                    <th data-field="results" data-sortable="false" id="results">文件一览</th>
                                    <th data-field="operation" data-sortable="false" id="operation">操作</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div id="update" class="modal fade modal-margin" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 600px;">
            <div class="modal-content">
                <div class="modal-header bg-primary">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">
                        <span id="lblAddTitle" style="font-weight: bold">修改样品名：</span>
                    </h4>
                </div>
                <form id="updateForm" data-toggle="validator">
                    <div class="modal-body">
                        <div class="row-fluid">

                            <div class="row">
                                <div class="col-sm-8">
                                    <div class="form-group">
                                        <label class="control-label">
                                            样品名：
                                        </label>
                                        <input class="form-control indent" id="samplename" name="samplename" readonly="readonly" >
                                    </div>
                                </div>

                                <div class="col-sm-8" style="display: none;" >
                                    <div class="form-group">
                                        <label class="control-label">
                                            ID：
                                        </label>
                                        <input class="form-control indent" id="sampleId" name="sampleId" readonly="readonly" >
                                    </div>
                                </div>


                                <div class="col-sm-8">
                                    <div class="form-group">
                                        <label class="control-label">
                                            新的样品名: </label>
                                        <input class="form-control indent" name="newsample" id="newsample" >
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="modal-footer bg-info">
                        <button type="submit" class="btn blue" onclick="sureUpdate()">确定</button>
                        <button type="button" class="btn green" data-dismiss="modal">取消</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div id="rest" class="modal fade modal-margin" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 1000px;">
            <div class="modal-content">
                <div class="modal-header bg-primary">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">
                        <span id="lblAddTitle" style="font-weight: bold">重新运行质控：</span>
                    </h4>
                </div>
                <form id="resetPEForm" data-toggle="validator" class="registration-form form-horizontal">
                    <div class="modal-body">
                        <div class="row-fluid">

                            <div class="form-group" style="display: none;">
                                <div class="col-sm-6 indent">
                                    <input name="proname" id="proname" class="form-control" />
                                </div>
                            </div>

                            <div class="form-group" style="display: none;">
                                <div class="col-sm-6 indent">
                                    <input name="Id" id="Id" class="form-control" />
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-8">样品名:</label>
                                <div class="col-sm-6 indent">
                                    <input name="sample" id="sample" class="form-control" readonly="readonly"/>
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="col-sm-6" id="trim_type"></label>
                                <label class="col-sm-1">
                                    <a id="down-1" style="margin-left: 2em">
                                        <i class="fa fa-arrow-down"></i>
                                    </a>
                                    <a id="up-1" style="margin-left: 2em;
                                        display: none">
                                        <i class="fa fa-arrow-up"></i>
                                    </a>
                                </label>
                            </div>

                            <div id="set-1" style="display: none" class="indent">

                                <div class="form-group">
                                    <p class="col-sm-7">
                                        Input FASTQ quality file scores encoding type:</p>
                                    <div class="col-sm-6 indent">
                                        <select class="form-control" name="encondingType" id="encondingType">
                                            <option value="-phred64">Illumina 1.3-1.7 Phred+64</option>
                                            <option value="-phred33">Illumina 1.8+ Phred+33</option>
                                        </select>
                                    </div>
                                </div>


                                <div class="form-group">
                                    <p class="col-sm-7">Perform initial ILLUMINACLIP step?:</p>
                                    <div class="col-sm-6 indent">
                                        <select class="form-control" name="stepMethod" id="stepMethod" onchange="stepChange(this)">
                                            <option value="yes">Yes</option>
                                            <option value="no">No</option>
                                        </select>
                                    </div>
                                </div>

                                <div id="stepValue" style="display: none;">
                                    <div class="form-group" id="pe">
                                        <p class="col-sm-7 indent">Adapter sequences to use:</p>
                                        <div class="col-sm-6 indent-1">
                                            <select class="form-control" name="adapter" id="adapter_pe">
                                                <option value="TruSeq2-PE.fa">
                                                    TruSeq2 (paired-ended, for Illumina GAII)</option>
                                                <option value="TruSeq3-PE.fa">
                                                    TruSeq3 (paired-ended, for MiSeq and HiSeq)</option>
                                                <option value="TruSeq3-PE-2.fa">
                                                    TruSeq3 (additional seqs) (paired-ended, for MiSeq and HiSeq)</option>
                                                <option value="NexteraPE-PE.fa">Nextera (paired-ended)</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group" id="se">
                                        <p class="col-sm-7 indent">Adapter sequences to use:</p>
                                        <div class="col-sm-6 indent-1">
                                            <select class="form-control" name="adapter" id="adapter_se">
                                                <option value="TruSeq2-SE.fa">
                                                    TruSeq2 (single-ended, for Illumina GAII)</option>
                                                <option value="TruSeq3-SE.fa">
                                                    TruSeq3 (single-ended, for MiSeq and HiSeq)</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group" >
                                        <p class="col-sm-7 indent">
                                            Maximum mismatch count which will still allow a full match to be performed:</p>
                                        <div class="col-sm-6 indent-1">
                                            <input name="seed_mismatches" id="seed_mismatches" class="form-control"/>
                                        </div>
                                    </div>

                                    <div class="form-group" >
                                        <p class="col-sm-7 indent">
                                            How accurate the match between the two 'adapter ligated' reads must be for PE palin
                                            drome read alignment:</p>
                                        <div class="col-sm-6 indent-1">
                                            <input name="palindrome_clip_threshold" id="palindrome_clip_threshold" class="form-control" />
                                        </div>
                                    </div>

                                    <div class="form-group" >
                                        <p class="col-sm-7 indent">
                                            How accurate the match between any adapter etc. sequence must be against a read:</p>
                                        <div class="col-sm-6 indent-1">
                                            <input name="simple_clip_threshold" id="simple_clip_threshold" class="form-control" />
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <p class="col-sm-7">Perform Sliding window trimming (SLIDINGWINDOW)?:</p>
                                    <div class="col-sm-6 indent">
                                        <select class="form-control" name="trimMethod" id="trimMethod" onchange="trimChange(this)">
                                            <option value="yes">Yes</option>
                                            <option value="no">No</option>
                                        </select>
                                    </div>
                                </div>

                                <div id="trimValue">
                                    <div class="form-group" >
                                        <p class="col-sm-7 indent">
                                            Number of bases to average across:</p>
                                        <div class="col-sm-6 indent-1">
                                            <input name="window_size" id="window_size" class="form-control" />
                                        </div>
                                    </div>

                                    <div class="form-group" >
                                        <p class="col-sm-7 indent">
                                            Average quality required:</p>
                                        <div class="col-sm-6 indent-1">
                                            <input name="required_quality" id="required_quality" class="form-control" />
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <p class="col-sm-7">Drop reads below a specified length (MINLEN)?:</p>
                                    <div class="col-sm-6 indent">
                                        <select class="form-control" name="minlenMethod" id="minlenMethod" onchange="minlenChange(this)">
                                            <option value="yes">Yes</option>
                                            <option value="no">No</option>
                                        </select>
                                    </div>
                                </div>

                                <div id="minlenValue">
                                    <div class="form-group" >
                                        <p class="col-sm-7 indent">
                                            Minimum length of reads to be kept:</p>
                                        <div class="col-sm-6 indent-1">
                                            <input name="minlen" id="minlen" class="form-control" />
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <p class="col-sm-7">
                                        Cut bases off the start of a read, if below a threshold quality (LEADING)?:</p>
                                    <div class="col-sm-6 indent">
                                        <select class="form-control" name="leadingMethod" id="leadingMethod" onchange="leadingChange(this)">
                                            <option value="yes">Yes</option>
                                            <option value="no">No</option>
                                        </select>
                                    </div>
                                </div>

                                <div id="leadingValue" style="display: none">
                                    <div class="form-group" >
                                        <p class="col-sm-7 indent">
                                            Minimum quality required to keep a base:</p>
                                        <div class="col-sm-6 indent-1">
                                            <input name="leading" id="leading" class="form-control"/>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <p class="col-sm-7">
                                        Cut bases off the end of a read, if below a threshold quality (TRAILING)?:</p>
                                    <div class="col-sm-6 indent">
                                        <select class="form-control" name="trailingMethod" id="trailingMethod" onchange="trailingChange(this)">
                                            <option value="yes">Yes</option>
                                            <option value="no">No</option>
                                        </select>
                                    </div>
                                </div>

                                <div id="trailingValue">
                                    <div class="form-group" >
                                        <p class="col-sm-7 indent">
                                            Minimum quality required to keep a base:</p>
                                        <div class="col-sm-6 indent-1">
                                            <input name="trailing" id="trailing" class="form-control" />
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <p class="col-sm-7">Cut the read to a specified length (CROP):</p>
                                    <div class="col-sm-6 indent">
                                        <select class="form-control" name="cropMethod" id="cropMethod" onchange="cropChange(this)">
                                            <option value="yes">Yes</option>
                                            <option value="no">No</option>
                                        </select>
                                    </div>
                                </div>

                                <div id="cropValue" style="display: none">
                                    <div class="form-group" >
                                        <p class="col-sm-7 indent">
                                            Number of bases to keep from the start of the read:</p>
                                        <div class="col-sm-6 indent-1">
                                            <input name="crop" id="crop" class="form-control" />
                                        </div>
                                    </div>

                                </div>

                                <div class="form-group">
                                    <p class="col-sm-7">
                                        Cut the specified number of bases from the start of the read (HEADCROP)?:</p>
                                    <div class="col-sm-6 indent">
                                        <select class="form-control" name="headcropMethod" id="headcropMethod" onchange="headcropChange(this)">
                                            <option value="yes">Yes</option>
                                            <option value="no">No</option>
                                        </select>
                                    </div>
                                </div>

                                <div id="headcropValue" style="display: none">
                                    <div class="form-group" >
                                        <p class="col-sm-7 indent">
                                            Number of bases to remove from the start of the read:</p>
                                        <div class="col-sm-6 indent-1">
                                            <input name="headcrop" id="headcrop" class="form-control" value="0" />
                                        </div>
                                    </div>
                                </div>
                            </div>


                        </div>
                    </div>
                    <div class="modal-footer bg-info">
                        <button type="button" class="btn blue" onclick="RunningPE()">运行</button>
                        <button type="button" class="btn green" data-dismiss="modal">取消</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div id="logShow" class="modal fade modal-margin" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 1000px;">
            <div class="modal-content">
                <div class="modal-header bg-primary">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">
                        <span id="lblAddTitle" style="font-weight: bold">日志信息：</span>
                        <button type="button" class="btn-remove" data-dismiss="modal" ><i class="fa fa-remove"></i></button>
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="row-fluid" id="logInfo">

                    </div>
                </div>

            </div>
        </div>
    </div>

    <div id="deleteShow" class="modal fade modal-margin" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="margin-top: 200px;">
        <div class="modal-dialog" style="width: 400px;">
            <div class="modal-content">
                <div class="modal-header bg-primary">
                    <h4 class="modal-title" align="center" id="title1">
                        <span id="deleteTitle" style="font-weight: bold">请确认是否删除样品"
                            <b id="dsample">

                            </b>"?
                        </span>
                    </h4>
                    <h4 class="modal-title" align="center" id="title2" style="display: none">
                        <span id="deleteTitle" style="font-weight: bold">删除中...</span>
                    </h4>
                    <h4 class="modal-title" align="center" id="title3" style="display: none">
                        <span id="deleteTitle" style="font-weight: bold">删除成功</span>
                    </h4>
                </div>
                <div class="row-fluid" align="center" >
                    <div id="warn1">
                        <img src="/assets/images/warning.png">
                    </div>
                    <div id="warn2" style="display: none;">
                        <img src="/assets/images/timg2.gif" style="height: 109px;">
                    </div>
                    <div id="warn3" style="display: none;">
                        <img src="/assets/images/success.png">
                    </div>
                </div>
                <div class="modal-footer bg-info">
                    <div align="center">
                        <button type="button" class="btn red" onclick="deleteSample(this)" style="width: 100px;" id="btn1">
                            确定</button>
                        <button type="button" class="btn green" data-dismiss="modal" style="width: 100px;" id="btn2">
                            取消</button>
                        <button type="button" class="btn green" onclick="updateDelete()" style="width: 100px;
                            display: none;" id="btn3">确定</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="@routes.Assets.at("javascripts/reset.js")" type="text/javascript"></script>
    <script>
            $(function () {
                formValidation();
                formValidation1();
                tableInformation();

                window.setInterval(function () {
                    $(".state").each(function (n, value) {
                        var st = value.value;
                        if (st == 0) {
                            updateTable();
                        }
                    })
                }, 3000);
            });


            function updateSample(obj) {
                var name = obj.value;
                var id = obj.id;
                $("#samplename").empty();
                $("#samplename").val(name);
                $("#sampleId").val(id);
                $("#update").modal("show")
            }

            function formValidation1() {
                $('#updateForm').formValidation({
                    framework: 'bootstrap',
                    icon: {
                        valid: 'glyphicon glyphicon-ok',
                        invalid: 'glyphicon glyphicon-remove',
                        validating: 'glyphicon glyphicon-refresh'
                    },
                    fields: {
                        newsample: {
                            validators: {
                                notEmpty: {
                                    message: '不能为空!'
                                },
                                different: {
                                    field: 'samplename',
                                    message: '不能与原样品名相同'
                                },
                                regexp: {
                                    regexp: '^[A-Za-z0-9"_"]{1,12}$',
                                    message: '12个以内字符，可使用字母、数字、下划线！'
                                },
                                stringLength: {
                                    message: '任务名长度最大为20！',
                                    max: function (value, validator, $field) {
                                        return 20 - (value.match(/\r/g) || []).length;
                                    }
                                },
                                remote: {
                                    type: 'GET',
                                    url: '@routes.SampleController.checkNewsample(proname)',
                                    message: '样品名重复，请重新输入'
                                }
                            }
                        }
                    }
                });
            }

            function sureUpdate() {
                var form = $("#updateForm")
                var fv = form.data("formValidation")
                fv.validate()
                if (fv.isValid()) {
                    var index = layer.load(1, {
                        shade: [0.1, '#fff']
                    });
                    $.ajax({
                        url: "@routes.SampleController.updateSample()",
                        type: "put",
                        dataType: "json",
                        data: $("#updateForm").serialize(),
                        success: function (data) {
                            if (data.valid == "true") {
                                layer.close(index);
                                $("#update").modal("hide")
                                cpm("table", "修改成功");
                            }
                        }
                    })
                }
            }


            function openDelete(obj) {
                var i = obj.id;
                var name = obj.value;
                $("#dsample").empty();
                $("#dsample").append(name);
                $("#btn1").val(i);
                deleteBefore();
                $("#deleteShow").modal("show");

            }

            function deleteSample(obj) {
                var id = obj.value;
                deleting();
                $.ajax({
                    url: "/project/deleteSample?id=" + id,
                    type: "delete",
                    dataType: "json",
                    success: function (data) {
                        if (data.valid == "true") {
                            deleteAfter();
                        }
                    }
                });
            }

            function updateDelete() {
                $("#deleteShow").modal("hide");
                updateTable();
            }

            function openLog(obj) {
                $("#logInfo").empty();
                var id = obj.value;
                $.ajax({
                    url: "/project/openLogFile?id=" + id,
                    type: "get",
                    dataType: "json",
                    success: function (data) {
                        $("#logInfo").append(data.log);
                        $("#logShow").modal("show")
                    }
                })
            }

            function tableInformation() {
                $.ajax({
                    url: "@routes.SampleController.getAllSample(proname)",
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        $('#table').bootstrapTable({data: data});
                    }
                })
            }

            function updateTable() {
                $.ajax({
                    url: "@routes.SampleController.getAllSample(proname)",
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        $("#table").bootstrapTable('load', data);
                    }
                });
            }

            function RunningPE() {
                var form = $("#resetPEForm")
                var fv = form.data("formValidation")
                fv.validate()
                if (fv.isValid()) {
                    $.ajax({
                        url: "/transcriptome/sample/resetPE",
                        type: "post",
                        dataType: "json",
                        data: $("#resetPEForm").serialize(),
                        success: function (data) {
                            if (data.valid == "true") {
                                $("#rest").modal("hide");
                                updateTable();
                                $.ajax({
                                    url: "/transcriptome/sample/isRunCmd?id=" + data.id,
                                    type: "post"
                                })
                            }
                        }
                    })
                }
            }


    </script>


}